package com.recycle.common;




import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.Serializable;

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ServerResponse<T> implements Serializable {
    private int status;
    private String msg;
    private T data;
    private ServerResponse(int status){
        this.status = status;
    }
    private ServerResponse(int status, String msg){
        this.status=status;
        this.msg=msg;
    }
    private ServerResponse(int status, T data){
        this.status =status;
        this.data = data;
    }
    private ServerResponse(int status, String msg, T data){
        this.status=status;
        this.msg=msg;
        this.data = data;
    }



    @JsonIgnore
    public boolean isSuccess(){
        return status== ResPonseCode.SUCCESS.getCode();
    }
    public int getStatus(){
        return status;
    }
    public T getData(){
        return data;
    }
    public String getMsg(){
        return msg;
    }
    public static <T> ServerResponse<T>  SuccessModel(int status){
        return new ServerResponse<T>(status);
    }
    public static <T>  ServerResponse<T> SuccessModelMessage(int status,String msg){
        return new ServerResponse<T>(status,msg);
    }
    public static <T> ServerResponse<T> SuccessModel(){
        return  new ServerResponse<T>(ResPonseCode.SUCCESS.getCode());
    }
    public static <T> ServerResponse<T> SuccessModel(String msg,T data){
        return  new ServerResponse<T>(ResPonseCode.SUCCESS.getCode(),msg,data);
    }
    public static <T> ServerResponse<T> SuccessModel(T data){
        return  new ServerResponse<T>(ResPonseCode.SUCCESS.getCode(),data);
    }
    public static <T> ServerResponse<T> SuccessModelMessage(String msg){
        return  new ServerResponse<T>(ResPonseCode.SUCCESS.getCode(),msg);
    }
    public static <T> ServerResponse<T>  ErrorModel(){
        return new ServerResponse<T>(ResPonseCode.ERROR.getCode());
    }
    public static <T> ServerResponse<T>  ErrorModel(int status){
        return new ServerResponse<T>(status);
    }
    public  static <T> ServerResponse<T> ErrorModelMessage(String msg){
        return new ServerResponse<T>(ResPonseCode.ERROR.getCode(),msg);
    }
    public static <T> ServerResponse<T>  ErrorModel(String msg,T data){
        return  new ServerResponse<T>(ResPonseCode.ERROR.getCode(),msg,data);
    }
    public static <T> ServerResponse<T> ErrorModelCodeMessage(int status,String msg){
        return  new ServerResponse<T>(status,msg);
    }
}
